<?php

use think\facade\Route;
use app\admin\middleware\LoginMiddleware;
use app\admin\middleware\AuthMiddleware;
use app\admin\middleware\OperationLog;

/**
 * 自动加载crud目录下的路由文件
 */
Route::group(function () {
    $path = $this->app->getRootPath() . 'app/admin/route/crud';
    if (is_dir($path)) {
        $files = scandir($path);
        foreach ($files as $file) {
            if ($file != '.' && $file != '..') {
                if (is_dir($path . '/' . $file)) {
                    $child_files = scandir($path . '/' . $file);
                    foreach ($child_files as $child_file) {
                        if ($child_file != '.' && $child_file != '..') {
                            include $path . '/' . $file . '/' . $child_file;
                        }
                    }
                } else {
                    include $path . '/' . $file;
                }
            }
        }
    }
})->middleware([
    LoginMiddleware::class,
    AuthMiddleware::class,
    OperationLog::class
]);